Path: blob/master/Part 3 - Classification/K Nearest Neighbors/[R] K-Nearest Neighbour.ipynb
1009 views
Kernel: R
K-Nearest Neighbour
Data preprocessing
In [1]:
In [2]:
Out[2]:
In [3]:
In [4]:
Out[4]:
In [5]:
Out[5]:
In [6]:
In [7]:
Out[7]:
In [8]:
Out[8]:
Fitting K-NN to the Training set and Predicting the test set result
In [19]:
In [21]:
Out[21]:
In [24]:
Out[24]:
Predictions are almost correct.
Making the Confusion Matrix
In [25]:
Out[25]:
y_pred
0 1
0 47 4
1 5 24
That's awesome. Only 5 + 4 = 9, incorrect prediction and 47 + 24 = 81 correct prediction.
Visualizing the Training set results
In [26]:
In [35]:
In [36]:
Out[36]:
Visualizing the Test set results
In [32]:
In [34]:
Out[34]:
Gist: K-NN is a non Linear Classifier. That's why it predicts so well in our decision making problem.